import { Injectable } from "@angular/core";
import axios from "axios";
import * as config from "src/assets/config/config.json";
import { ConfigServiceService } from "./configService.service";

@Injectable({
  providedIn: "root",
})
export class AxiosService {
  // public config;
  public domainTest:any;
  public domainTest1:any;
  constructor(public configServiceService: ConfigServiceService) {
    this.domainTest = this.configServiceService.getSpecificConfigure('datasources').apiUrl;
    this.domainTest1 = this.configServiceService.getSpecificConfigure('datasources').apiUrl;
  }

  // domainTest: any = this.config.apiUrl;
  // // public domainTest: any = 'http://fsms-api.api.10.66.224.2.k8sprd-wks.k8s.wistron.com/';
  // public domainTest1: any = config.apiUrl; // 下载
  // constructor() {}

  // url:请求域名后面的拼接路径
  axiosGet(url: any) {
   
    
    // debugger
    return new Promise((success, err) => {
      axios
        .get(this.domainTest + url)
        .then(function (response) {
          success(response.data);
        })
        .catch(function (error) {
          // debugger
          err(error);
        });
    });
  }

  // url:请求域名后面的拼接路径;data:请求的参数;timeout:超时时间
  axiosPost(url: any, data?, config?) {
    // debugger
    return new Promise((success, err) => {
      if (data) {
        axios
          .post(this.domainTest + url, data, config)
          .then(function (response) {
            success(response.data);
          })
          .catch(function (error) {
            err(error);
          });
      } else {
        axios
          .post(this.domainTest + url)
          .then(function (response) {
            success(response.data);
          })
          .catch(function (error) {
            err(error);
          });
      }
    });
  }
}
